package com.win.cn.control;


import com.win.cn.core.model.SoftwareModel;
import com.win.cn.service.SoftWareService;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;

/**
 * 软件启动
 * 
 * @author wangzh
 * 2018年6月9日 下午3:20:07
 */
public class SoftWareControl {
		 
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public SplitPane createTableView(){
		
		SoftWareService softwareService=new SoftWareService();
		
		SplitPane splitPane=new SplitPane();
		//按钮
		AnchorPane startPane=new  AnchorPane();
		startPane.setMinWidth(100);
		startPane.setMaxWidth(100);
		
		VBox  hbox=new VBox();
		Button startBtn=new Button("启动");
		
		startBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
            	softwareService.startSoftWare();
            }
        });
		
		Button addBtn=new Button("添加");
		
		hbox.getChildren().addAll(startBtn,addBtn);
		
		startPane.getChildren().add(hbox);
		startPane.setPadding(new Insets(10,10,0,0));
		
//		Image imageOk = new Image(getClass().getResourceAsStream("ok.png"));  
//		Button button3 = new Button("Accept", new ImageView(imageOk)); 
		
		//软件列表
		TableView<SoftwareModel> softwareTable=new TableView<>();
		
		TableColumn softName=new TableColumn("软件名");
		softName.setMinWidth(100);
		softName.setCellValueFactory(new PropertyValueFactory<>("softName"));
		TableColumn url=new TableColumn("路径");
		url.setMinWidth(300);
		url.setCellValueFactory(new PropertyValueFactory<>("url"));
		TableColumn time=new TableColumn("时间");
		time.setMinWidth(100);
		time.setCellValueFactory(new PropertyValueFactory<>("time"));
		
		
//		time.setVisible(false);
		
		ObservableList<SoftwareModel> softdata = FXCollections.observableArrayList();
		softwareService.addData(softdata);
        
		softwareTable.setItems(softdata);
        softwareTable.getColumns().addAll(softName,url,time);
        
        splitPane.getItems().addAll(softwareTable,startPane);
        
        
        
        
		return splitPane;
	}
	
	

	

	

}
